

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-11
 * Time: 16:41
 */
public class MyQueue {//尾插头删
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val){
            this.val=val;
        }
    }

    public ListNode head;
    public ListNode last;
    public int usedSize;

    public void offer(int e){//入列
        ListNode node=new ListNode(e);
        if(head==null){
            head=last=node;
        }else{
            node.prev=last;
            last.next=node;
            last=last.next;
        }
        usedSize++;
    }

    public int poll(){//出列
        if(head==null){
            throw new EmptyQueueException();
        }
        int val=head.val;
        head=head.next;
        if(head!=null){
            head.prev=null;
        }
        usedSize--;
        return val;
    }

    public int peek(){
        if(head==null){
            throw new EmptyQueueException();
        }
        return head.val;
    }

    public int size(){
        return usedSize;
    }

    public boolean isEmpty(){
        return usedSize==0;
    }

}
